<template>
	<view>
		<nav-bar   fontColor="#FFFFFF" title="确认领取">
			<!-- <view @click="onPageJump('/pages/event/goRemoval')" slot="right" class="search_box"></view> -->
		</nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<!-- <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" style="margin-top: 20rpx;"
		 @up="upCallback" :up="upOption"> -->
		<!-- <view v-if="!locationNo">
			<view @click="goQrCode" class="imgCode">
				<image class="qrImg" src="../../static/icon/scan.png"></image>
				<view class="qrTitle">请扫描库位二维码标签</view>
			</view>
		</view> -->
		<view>
			<view class="orderNumber">数量：{{textData.length}}个</view>
			<!-- <view class="orderNumber">库位号：{{locationNo}}</view> -->
			<!-- <view class="orderNumber">借用数：{{textData.length}}个</view>
			<view v-for="(item,index) in dataList">
				<uni-list>
					<uni-list-item :disabled="item.status == 'outed' ? true : false" :index="index+1"
						@click="onPageJump('/pages/event/uploadFile?id='+item.materialNo)"
						:title="'物品名称:'+item.materialName + '\n物品编号:'+item.materialNo"
						:note="'案件名称:'+item.caseName + '\n'+ '案件编号:'+item.caseNo + '\n'+ '库位编号:'+ item.locationNo"
						rightText="上传" link="reLaunch" clickable>
					</uni-list-item>
				</uni-list>
			</view>
			<view style="height: 150rpx;">
				<view style="position: fixed;bottom: 20rpx;width: 100%;z-index: 999;">
					<button @click="goNext"
						style="background: #3B5DE0;color: #FFFFFF;border-radius: 10rpx;width: 90%;height: 100rpx;margin: 0 auto;letter-spacing: 5rpx;">提交</button>
				</view>
			</view> -->
			<view v-if="!status">
				<view class="imgCode">
					<image class="qrImg" src="../../static/icon/scanning_ico.png"></image>
					<view class="qrTitle">请扫描RFID射频标签</view>
				</view>
				<view class="buttonBox">
					<button class="button_fix" @click="goNext" size="default">下一步</button>
				</view>
			</view>
			<view v-else>
				<view v-for="(item,index) in textData">
					<uni-list>
						<uni-list-item :index="index+1"
							:title="'物品名称:'+item.itemName + '\n物品编号:'+item.serialNo" @click="onPageJump('/pages/event/uploadFile?id='+item.serialNo)"
							:note="'案件名称:'+item.caseName + '\n'+ '案件编号:'+item.caseNo" rightText="上传" link="reLaunch"
							clickable>
						</uni-list-item>
					</uni-list>
				</view>
				<view style="height: 120rpx;">
					<view style="position: fixed;bottom: 20rpx;width: 100%;z-index: 999;">
						<!-- <button @click="startCheck" type="primary"
							style="width: 90%;margin: 0 auto;background:#3B5DE0;margin-bottom: 20rpx;">清除盘点</button>
						<button @click="goNext" type="primary"
							style="width: 90%;margin: 0 auto;background:#3B5DE0;">提交盘点</button> -->
							<view class="buttonBox">
								<button class="button_fix" @click="goBack" size="default">返回</button>
								<button class="button_fix" @click="submit" size="default">提交</button>
							</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认" title="通知" content="xxx"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog :deleteIcon="true" :dataList="textData" title="确认信息" ref="inputClose" @confirm="confirm"
				mode="scroll">
			</uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="3000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="hintDialog" type="dialog">
			<uni-popup-dialog :beforeClose="true" type="info" cancelText="返回首页" confirmText="继续领取" title="提示"
				content="还有其他物品需要继续确认领取吗？" @confirm="hintConfirm" @close="hintClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	var main = null;
	var receiver = null;
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import uniList from '@/components/uni-list/uni-list.vue';
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			uniList,
		},
		data() {
			return {
				// btnnum: 0, //topbar
				// array: ['领取', '借用', '处理'],
				// index: 0,
				popStatus: uni.getStorageSync('lingqu'),
				msgType: 'success',
				messageText: '这是一条成功提示',
				orderNumber: "10",
				//搜索内容
				downOption: {
					native: false,
					use: true, // 是否启用下拉刷新; 默认true
					auto: true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: false,
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
				},
				dataList: [],
				// locationNo: '',
				repeactId: [],
				rfId: [],
				status: false,
				textData: [
					// {
					// 	itemName: '华为手机测试',
					// 	caseName: '卢湾瑞金街道寻衅殴打滋事案',
					// 	serialNo: 'W3101159200002020090044',
					// 	caseNo: 'A3101155000002021086691',
					// 	rfidCode: '1'
					// },
					// {
					// 	itemName: '华为手机测试',
					// 	caseName: '卢湾瑞金街道寻衅殴打滋事案',
					// 	serialNo: 'W3101159200002020090044',
					// 	caseNo: 'A3101155000002021086691',
					// 	rfidCode: '1'
					// },
					// {
					// 	itemName: '华为手机测试',
					// 	caseName: '卢湾瑞金街道寻衅殴打滋事案',
					// 	serialNo: 'W3101159200002020090044',
					// 	caseNo: 'A3101155000002021086691',
					// 	rfidCode: '1'
					// }
				]
			};
		},
		onLoad() {
			// this.test()
			this.get_gb();

		},
		onReady() {
			if (this.popStatus) {
				this.dialogToggle('info')
			}
		},
		onBackPress() {
			if (receiver != null) {
				main.unregisterReceiver(receiver)
			}
		},
		onShow() {

		},
		//方法
		methods: {
			// bindPickerChange: function(e) {
			// 	console.log('picker发送选择改变，携带值为', e.target.value)
			// 	this.index = e.target.value
			// },
			hintConfirm() {
				this.$refs.hintDialog.close();
			},
			hintClose() {
				this.$refs.hintDialog.close();
				uni.navigateBack({
					delta: 1
				});
			},
			test() {
				let opt = {
					url: 'oms/tbRelateItemTakeDetail/outbound',
					method: 'POST'
				};
				let params = {
					rfidCodes: ['45']
				};
				this.$http.httpTokenRequest(opt, params).then(res => {

				})
			},
			confirm() {
				// this.$refs.inputDialog.open();
				if (this.textData == '') {
					this.messageToggle('error', '请扫描RFID射频标签')
					this.$refs.inputDialog.close();

				} else {
					// this.submit()
					this.status = !this.status
					this.$refs.inputDialog.close();
				}
			},
			goBack(){
				this.status = !this.status
			},
			messageToggle(type, msg) {
				this.msgType = type
				this.messageText = msg
				this.$refs.message.open();
			},
			dialogConfirm() {
				uni.setStorageSync('lingqu', false)
				console.log('确认')
				this.$refs.alertDialog.close()
			},
			dialogToggle(type) {
				this.msgType = type
				this.$refs.alertDialog.open()
			},
			dialogClose() {
				console.log('取消')
				this.$refs.alertDialog.close()
			},
			// goQrCode() {
			// 	var that = this;
			// 	uni.scanCode({
			// 		success: function(res) {
			// 			console.log('条码类型：' + res.scanType);
			// 			console.log('条码内容：' + res.result);
			// 			that.locationNo = res.result
			// 			that.getDataList();
			// 		}
			// 	});
			// },
			get_gb() {
				var that = this;
				main = plus.android.runtimeMainActivity();
				receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						var data = intent.getExtra("data");
						if (data) {
							if (that.textData == '') {
								that.repeactId = []
								that.rfId = [];
							}
							that.repeactId.push(data)
							for (let i = 0; i < that.repeactId.length; i++) {
								if (that.rfId.indexOf(that.repeactId[i]) == -1) {
									that.rfId.push(that.repeactId[i])
									that.pushArray(that.repeactId[i]);
								}
							}
						}
					}
				});
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				let filter = new IntentFilter();
				filter.addAction('android.rfid.epccode');
				var info = main.registerReceiver(receiver, filter)
				// main.unregisterReceiver(receiver)
			},
			pushArray(e) {
				var that = this;
				let opt = {
					url: 'oms/tbRelateItemTakeDetail/search',
					method: 'POST'
				};
				let params = {
					rfidCode: e
				};
				that.$http.httpTokenRequest(opt, params).then(res => {
					console.log(res)
					that.textData.push({
						itemName: res.data.data[0].itemName,
						caseName: res.data.data[0].caseName,
						serialNo: res.data.data[0].serialNo,
						caseNo: res.data.data[0].caseNo,
						rfidCode: e
					})
				})
			},
			goNext() {
				if (this.textData == '') {
					this.messageToggle('error', '请扫描RFID射频标签')
				} else {
					this.$refs.inputDialog.open();
				}
			},
			submit() {
				let codeRfid = [];
				for (let i = 0; i < this.textData.length; i++) {
					codeRfid.push(this.textData[i].rfidCode)
				}
				let opt = {
					url: 'oms/tbRelateItemTakeDetail/outbound',
					method: 'POST'
				};
				let params = {
					rfidCodes: codeRfid,
					optType: '确认领取'
				};
				console.log(params)
				this.$http.httpTokenRequest(opt, params).then(res => {
					console.log(res)
					if (res.data.code == 200) {
						this.messageToggle('success', res.data.msg)
						this.status = !this.status
						this.$refs.hintDialog.open();
						this.textData = []
						this.repeactId = []
						this.rfId = []
						this.getDataList();
					} else {
						this.messageToggle('error', res.data.msg)
						this.status = !this.status
						this.textData = []
						this.repeactId = []
						this.rfId = []
						return
					}
				})
			},
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},

			/*下拉刷新的回调 */
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				this.loadData(page.num);
			},
			loadData(pageNo) {
				let opts = {
					url: 'mesg/yunheFireOrEventMesg/search/' + pageNo + '/' + 10,
					method: 'POST'
				};
				let params = {
					eventType: '林业巡检',
					// contactId: uni.getStorageSync('userInfo').data.sysUser.id,
					// status: 'COMPLETED'
				};
				this.$http.httpTokenRequest(opts, params).then(res => {
						if (res.data.code == 200) {
							this.mescroll.endSuccess(res.data.data.records.length)
							if (pageNo == 1) {
								this.dataList = res.data.data.records;
							} else {
								this.dataList = this.dataList.concat(res.data.data.records);
							}
							this.orderNumber = res.data.data.total
							console.log(this.dataList)
							uni.hideLoading();
						} else if (res.data.code == 401) {
							uni.hideLoading();
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								position: 'center'
							});
							setTimeout(() => {
								uni.navigateTo({
									url: './homePage'
								})
							}, 1500)
						} else {
							uni.hideLoading();
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								position: 'center'
							});
						}
					})
					.catch(res => {
						this.mescroll.endErr();
						uni.hideLoading();
					});
			}
		},
		//页面下来刷新
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000);
		}
	};
</script>
<style>

	page {
		background: #FFFFFF;
	}
	.orderNumber {
		padding: 30rpx;
		font-size: 35rpx;
		font-weight: 700;
		letter-spacing: 3rpx;
		text-align: center;
		/* margin-top: 50rpx; */
	}
	.imgCode {
		position: relative;
		background: linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) left bottom,
			linear-gradient(#000000, #000000) left bottom;
		background-repeat: no-repeat;
		background-size: 2px 20px, 20px 2px;
		height: 400rpx;
		width: 400rpx;
		margin: 0 auto;
		margin-top: 35%;
	}

	.qrImg {
		width: 250rpx;
		height: 250rpx;
		left: 20%;
		top: 15%;
	}

	.qrTitle {
		font-size: 28rpx;
		color: #3B5DE0;
		margin-top: 90rpx;
		text-align: center;
		letter-spacing: 3rpx;
	}
	.buttonBox {
		width: 80%;
		margin: 0 auto;
		display: flex;
		margin-top: 200rpx;
		// z-index: 999;
	}
	
	.button_fix {
		width: 40%;
		height: 70rpx;
		margin: 0 auto;
		color: #FFFFFF;
		background: #2749C8;
		font-weight: bold;
		letter-spacing: 5rpx;
		// opacity: 0.9;
		font-size: 28rpx;
		line-height: 70rpx;
		
	}

</style>
